package com.tarzan.common.core.base;

/**
 * @author liujinshan
 * @title: BaseResponse
 * @projectName tarzan-cloud
 * @description: TODO 封装统一返回结果
 * @date 2021-5-17 21:15
 */
public class BaseResponse<T> {

    /**
     * 返回的对象结果
     */
    private T data;
    /**
     * 返回错误编码
     */
    private String errCode;
    /**
     * 返回错误信息
     */
    private String errMsg;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getErrCode() {
        return errCode;
    }

    public void setErrCode(String errCode) {
        this.errCode = errCode;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }


    public static <T> BaseResponse<T> ok(T o) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setData(o);
        response.setErrCode("200");
        response.setErrMsg("成功");
        return response;
    }



    public static <T> BaseResponse<T> ok(){
        BaseResponse<T> response = new BaseResponse<>();
        response.setErrCode("200");
        response.setErrMsg("成功");
        return response;
    }


    public static <T> BaseResponse<T> error(String code,String msg){
        BaseResponse<T> response = new BaseResponse<>();
        response.setErrCode(code);
        response.setErrMsg(msg);
        return response;
    }

}
